<template>
  <div style="padding: 30px">
    <el-form
      ref="ruleFormRef"
      :model="queryParams"
      :rules="rules"
      class="demo-ruleForm"
      :size="formSize"
      :inline="true"
      status-icon
    >
      <el-form-item label="参赛队类型" prop="queryParams" v-if="!toggle">
        <el-select v-model="queryParams.type" placeholder="全部">
          <el-option label="全部" value="" />
          <el-option label="俱乐部" value="0" />
          <el-option label="事业单位" value="1" />
          <el-option label="道馆" value="2" />
          <el-option label="企业" value="3" />
          <el-option label="机关" value="4" />
          <el-option label="其他" value="5" />
        </el-select>
      </el-form-item>
      <el-form-item label="机构（参赛队）名称" prop="region" v-else>
        <el-input v-model="queryParams.groupName" />
      </el-form-item>

      <el-form-item label="参赛单位" prop="queryParams" v-if="!toggle">
        <el-input v-model="queryParams.groupName" />
      </el-form-item>
      <el-form-item label="队伍名称" prop="queryParams" v-else>
        <el-input v-model="queryParams.teamName" />
      </el-form-item>
      <el-form-item label="报名状态" prop="queryParams" v-if="!toggle">
        <el-select v-model="queryParams.signStatus" placeholder="">
          <el-option label="全部" value="" />
          <el-option label="未提交" value="0" />
          <el-option label="已提交" value="1" />
          <el-option label="已付款" value="2" />
          <el-option label="审核拒绝" value="3" />
          <el-option label="被清除" value="4" />
          <el-option label="审核通过" value="5" />
          <el-option label="被取消" value="6" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery" icon="Search">
          查询
        </el-button>
        <el-button @click="resetQuery" icon="Refresh">重置</el-button>
        <el-button type="warning" @click="importFN" 
          >导出</el-button
        >
        
      </el-form-item>
    </el-form>

    <el-radio-group v-model="tabPosition">
      <el-radio-button @change="groupSign" label="报名参赛队"></el-radio-button>
      <el-radio-button @change="teamSign" label="队伍报名"></el-radio-button>
    </el-radio-group>

    <br />
    <br />
    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="tableData">
      <el-table-column
        label="序号"
        width="50"
        type="index"
        align="center"
      ></el-table-column>
      <el-table-column
        label="赛事名称"
        width="120"
        prop="cptName"
        align="center"
      ></el-table-column>

      <el-table-column
        label="参赛单位"
        min-width="100"
        prop="groupName"
        align="center"
      >
        <template #default="props">
          <div>
            {{ props.row.groupName || "/" }}
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="团体类型"
        min-width="100"
        prop="groupTypeStr"
        align="center"
      >
        <template #default="props">
          <div>
            {{ props.row.groupTypeStr || "/" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="所在地区"
        min-width="100"
        prop="city"
        align="center"
      >
        <template #default="props">
          <div>
            {{ props.row.city || "/" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="联系人"
        min-width="100"
        prop="contactPerson"
        align="center"
      >
        <template #default="props">
          <div>
            {{ props.row.contactPerson || "/" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="联系方式"
        prop="telNo"
        min-width="100"
        align="center"
      >
        <template #default="props">
          <div>
            {{ props.row.telNo || "/" }}
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="参赛人数"
        min-width="100"
        prop="players"
        align="center"
      ></el-table-column>
      <el-table-column
        label="参赛人次"
        min-width="100"
        prop="playerTimes"
        align="center"
      ></el-table-column>
      <el-table-column
        label="报名状态"
        min-width="100"
        prop="statusStr"
        align="center"
      ></el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>

<script setup>
import { groupCountsList, removeSign } from "@/api/match/data.js";
import { useRoute } from "vue-router";
import { useRouter } from "vue-router";
import { getCurrentInstance, ref } from "vue";
const tabPosition = ref("报名参赛队");
const router = useRoute();
const route = useRouter();
const cptId = ref(router.query.id);
const tableData = ref([]);
const total = ref(0);
const loading = ref(true);
const toggle = ref(false);
const { proxy } = getCurrentInstance();
const data = reactive({
  queryParams: {
    cptId: cptId,
    type: "",
    flag: toggle.value ? 1 : 0,
    groupName: undefined,
    teamName: undefined,
    pageSize: 10,
    pageNum: 1,
    signStatus:undefined
  },
  ruleForm: {},
});
const { ruleForm, queryParams } = toRefs(data);
onMounted(() => {
  getList();
});

async function getList() {
  loading.value = true;
  let res = await groupCountsList(queryParams.value);
  loading.value = false;
  tableData.value = res.rows;
  total.value = res.total;
  console.log(res);
}

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  if (toggle.value) {
    queryParams.value.type = undefined;
    queryParams.value.groupName = undefined;
    queryParams.value.teamName = undefined;
    queryParams.value.pageNum = 1;
    queryParams.value.pageSize = 10;
    queryParams.value.signStatus=undefined
    teamSign();
  } else {
    queryParams.value.type = undefined;
    queryParams.value.groupName = undefined;
    queryParams.value.teamName = undefined;
    queryParams.value.pageNum = 1;
    queryParams.value.pageSize = 10;
    queryParams.value.signStatus=undefined
    groupSign();
  }
}

//清除报名
async function remove(row) {
  let form = {
    type: toggle.value ? 1 : 0,
    id: row.signId,
    cptId: row.cptId,
  };

  let res = await removeSign(form);
  if (res.code == 200) {
    getList();
    proxy.$modal.msgSuccess("清除成功！");
  } else {
    proxy.$modal.msgError("清除失败！");
  }
}

//团队报名
function groupSign() {
  toggle.value = false;
  queryParams.value.flag = 0;
  queryParams.value.type = undefined;
  queryParams.value.groupName = undefined;
  queryParams.value.teamName = undefined;
  queryParams.value.pageNum = 1;
  queryParams.value.pageSize = 10;
  getList();
}

//队伍报名
function teamSign() {
  toggle.value = true;
  queryParams.value.flag = 1;
  queryParams.value.type = undefined;
  queryParams.value.groupName = undefined;
  queryParams.value.teamName = undefined;
  queryParams.value.pageNum = 1;
  queryParams.value.pageSize = 10;
  getList();
}

/** 导出按钮操作 */
function importFN() {
  queryParams.value.type = "";
  proxy.download(
    "/league/sign/exportLeagueSignGroup",
    {
      ...queryParams.value,
    },
    `job_log_${new Date().getTime()}.xlsx`
  );

}
</script>

<style scope></style>
